<template>
  <view class="app-container">
    <view>开发中...</view>
    <view class="version-view hor-layout-side-center">
      <view class="ver-layout">
        <view>app版本号：<span class="num-text">{{ versionObj.app }}</span></view>
        <view>wgt版本号：<span class="num-text">{{ versionObj.wgt }}</span></view>
      </view>
      <view>
        <u-button size="mini" type="primary" @click="checkUpdate">检查更新</u-button>
      </view>
    </view>
    <check-update></check-update>
  </view>
</template>

<script>
import update from "@/uni_modules/uni-upgrade-center-app/utils/check-update"
import checkUpdate from "../../components/check-update/check-update";

export default {
  name: "mine",
  components: {
    checkUpdate
  },
  data() {
    return {
      versionObj: {app: '非原生环境', wgt: '非原生环境'}
    }
  },
  computed: {},
  onLoad() {
    this.getAppVersion()
  },
  methods: {
    getAppVersion() {
      // #ifdef APP-PLUS
      this.versionObj.app = plus.runtime.version
      plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
        this.versionObj.wgt = widgetInfo.version
      })
      // #endif
    },
    checkUpdate() {
      update().then(res => {
        console.log("checkUpdate-res", res)
        if (res.result && res.result.message) this.$u.toast(res.result.message);
        if (res.message) this.$u.toast(res.message);
      }).catch(err => {
        console.log("checkUpdate-err", err)
        this.$u.toast(err.message)
      })
    }
  }
}
</script>

<style scoped>
.version-view {
  width: 100%;
  padding: 10px;
  margin: 10px 0px;
  border-radius: 7px;
  border: 1px solid lightgrey;
}

.num-text {
  color: lightcoral;
}
</style>
